package com.weixin.xplore.service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import com.weixin.xplore.dao.entity.SysSetting;
import com.weixin.xplore.dao.service.SysSettingDaoService;
import com.weixin.xplore.dao.service.SysUserDaoService;
import com.weixin.xplore.service.SysSettingBizService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class SysSettingBizServiceImpl implements SysSettingBizService {
    private final SysSettingDaoService service;

    @Override
    public <T> T queryValueByKey(String key, Class<T> tClass) {
        SysSetting sysSetting = service.queryByKey(key);
        if (ObjectUtil.isNull(sysSetting)) {
            return null;
        }
        String settingValue = sysSetting.getSettingValue();

        return Convert.convert(tClass, settingValue);
    }

    @Override
    public <T> T queryValueByKey(String key, Class<T> tClass, T defaultValue) {
        T t = queryValueByKey(key, tClass);
        return ObjectUtil.defaultIfNull(t,defaultValue);
    }
}
